home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / comm / revrdist.sit / RevRdist / RevRdist src / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-26  |  5.4 KB  |  222 lines  |  [TEXT/KAHL]

  1. /*
  2.  * messages.c - help with formatting and display of messages
  3.  */
  4. #include "RevRdist.h"
  5. #include <TransSkelProto.h>
  6. #include <TransDisplayProto.h>
  7.  
  8. extern StringPtr    syserrlist (OSErr);
  9.  
  10.  
  11. /*
  12.  *=========================================================================
  13.  * dispIndStr (w, idx, str, p0, p1, p2, p3) - display STR# with params
  14.  * entry:    w = TransDisplay window to display text in
  15.  *            idx = string index in STR# resource
  16.  *            str = STR# resource id
  17.  *            p0, p1, p2, p3 = strings to substitute into text, if fewer
  18.  *                than 4 strings are needed, end list early with nil
  19.  *=========================================================================
  20.  */
  21.  
  22. void
  23. dispIndStr (w, idx, str, p0, p1, p2, p3)
  24.     WindowPtr        w;
  25.     Integer            idx;
  26.     Integer            str;
  27.     StringPtr        p0, p1, p2, p3;
  28. {
  29.     Handle            h;
  30.     WindowPtr        oldw;
  31.     Longint            offset;
  32.     Size            len;
  33.  
  34.     if (w == nil)
  35.         return;
  36.     h = NewHandle ((Size) 256);
  37.     if (h == nil)
  38.         return;
  39.     GetDWindow (&oldw);                /* remember current window */
  40.     if (w != oldw)
  41.         SetDWindow (w);                /*  and switch to new window */
  42.     HLock (h);
  43.     GetIndString ((StringPtr) (*h), str, idx);
  44.     if (**h == 0)
  45.         goto eexit;
  46.     HUnlock (h);
  47.     SetHandleSize (h, (Size) (**h) + 1);
  48.     /*
  49.      * For each parameter up to a nil ptr, use Munger to insert it in
  50.      * the text.
  51.      */
  52.     offset = 1;
  53.     if (!p0)
  54.         goto done;
  55.     offset = Munger (h, offset, (Ptr) "^0", 2, &p0[1], (long) p0[0]);
  56.     if (offset < 0)
  57.         goto done;
  58.     if (!p1)
  59.         goto done;
  60.     offset = Munger (h, offset, (Ptr) "^1", 2, &p1[1], (long) p1[0]);
  61.     if (offset < 0)
  62.         goto done;
  63.     if (!p2)
  64.         goto done;
  65.     offset = Munger (h, offset, (Ptr) "^2", 2, &p2[1], (long) p2[0]);
  66.     if (offset < 0)
  67.         goto done;
  68.     if (!p3)
  69.         goto done;
  70.     offset = Munger (h, offset, (Ptr) "^3", 2, &p3[1], (long) p3[0]);
  71.  
  72. done:
  73.     HLock (h);
  74.     if (w == ActivityWind && Depth > 0)
  75.         DisplayText("          ", (Longint)(Depth <= 10 ? Depth : 10));
  76.     len = GetHandleSize (h) - 1;
  77.     DisplayText ((*h)+1, len);
  78.     DisplayLn ();
  79.     if (w == ActivityWind)
  80.     {
  81.         if (len > 255)
  82.             len = 255;
  83.         **h = len;
  84.         statMsg (*(StringHandle)h);
  85.     }
  86. eexit:
  87.     HUnlock (h);
  88.     DisposHandle (h);
  89.     if (w != oldw)
  90.         SetDWindow (oldw);
  91. }
  92.  
  93.  
  94. /*
  95.  *=========================================================================
  96.  * notice (idx, p0, p1, p2, p3) - write msg to activity window
  97.  * entry:    idx = index (L_xxx) of message text
  98.  *            p0, ... = strings to substitute in text
  99.  *=========================================================================
  100.  */
  101. void
  102. notice (idx, p0, p1, p2, p3)
  103.     Integer            idx;
  104.     StringPtr        p0, p1, p2, p3;
  105. {
  106.     int    i;
  107.     StringPtr        ap0, ap1, ap2, ap3;
  108.     unsigned char    cbuf[20];
  109.     
  110.     i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? ((ap3=p3) ? 4: 3) : 2) : 1) : 0;
  111.     switch (i)
  112.     {
  113.     case 0:    ap0 = Clue0;
  114.     case 1: ap1 = Clue1;
  115.     case 2: ap2 = Clue2;
  116.     case 3: ap3 = Clue3;
  117.     }
  118.     if (idx == L_SYS && p2 == nil)
  119.         ap2 = syserrlist (ClueID);
  120.     if (idx == L_FILE && (i < 1 || p1 == nil))
  121.         ap1 = syserrlist (ClueID);
  122.     dispIndStr (ActivityWind, idx, LST_STR, ap0, ap1, ap2, ap3);
  123. }
  124.  
  125.  
  126. /*
  127.  *=========================================================================
  128.  * panic (f, idx, p0, p1, p2) - display panic alert
  129.  * entry:    f = false if user can choose to ignore error
  130.  *            idx = index in ERR_STR of text
  131.  *            p0, p1, p2 = substitutable text
  132.  * exit:    Quit set true if user selects CANCEL
  133.  *=========================================================================
  134.  */
  135.  
  136. void
  137. panic (f, idx, p0, p1, p2)
  138.     Boolean            f;
  139.     Integer            idx;
  140.     StringPtr        p0, p1, p2;
  141. {
  142.     Integer    i;
  143.     Integer oldresfile;
  144.     StringPtr        ap0, ap1, ap2, ap3;
  145.     Str255            buf;
  146.     unsigned char    cbuf[20];
  147.     
  148.     i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? 3 : 2) : 1) : 0;
  149.     switch (i)
  150.     {
  151.     case 0:    ap0 = Clue0;
  152.     case 1: ap1 = Clue1;
  153.     case 2: ap2 = Clue2;
  154.     }
  155.     if (idx == E_SYS && (i < 2 || p2 == nil))
  156.         ap2 = syserrlist (ClueID);
  157.     if (idx == E_FILE && (i < 1 || p1 == nil))
  158.         ap1 = syserrlist (ClueID);
  159.     oldresfile = CurResFile ();
  160.     UseResFile (Ap_refNum);
  161.     GetIndString (buf, ERR_STR, idx);
  162.     ParamText (ap0, ap1, ap2, buf);
  163.     if (f)
  164.         i = StopAlert (RSRC_BASE+ALERT_PANIC, nil);
  165.     else
  166.         i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
  167.     if (f || i == ALRT_CANCEL)
  168.         Quit = true;
  169.     UseResFile (oldresfile);
  170. }
  171.  
  172. /*
  173.  *=========================================================================
  174.  * warning (idx, p0, p1, p2, p3) - display warning message
  175.  *         in the error and activity windows
  176.  *        and produce an alert unless we are the startup application
  177.  * entry:    idx = index in ERR_STR STR# of text
  178.  *            p0, p1, p2 = substitutable text
  179.  *=========================================================================
  180.  */
  181.  
  182. void
  183. warning (idx, p0, p1, p2)
  184.     Integer        idx;
  185.     StringPtr    p0, p1, p2;
  186. {
  187.     Integer    i;
  188.     static    oldidx    = -1;
  189.     Integer oldresfile;
  190.     StringPtr        ap0, ap1, ap2, ap3;
  191.     Str255            buf;
  192.     unsigned char    cbuf[20];
  193.     
  194.     i = (ap0=p0) ? ((ap1=p1) ? ((ap2=p2) ? 3 : 2) : 1) : 0;
  195.     switch (i)
  196.     {
  197.     case 0:    ap0 = Clue0;
  198.     case 1: ap1 = Clue1;
  199.     case 2: ap2 = Clue2;
  200.     }
  201.     if (idx == E_SYS && (i < 2 || p2 == nil))
  202.         ap2 = syserrlist (ClueID);
  203.     if (idx == E_FILE && (i < 1 || p1 == nil))
  204.         ap1 = syserrlist (ClueID);
  205.     oldresfile = CurResFile ();
  206.     UseResFile (Ap_refNum);
  207.     dispIndStr (ActivityWind, idx, ERR_STR, ap0, ap1, ap2, nil);
  208.     dispIndStr (ErrorWind, idx, ERR_STR, ap0, ap1, ap2, nil);
  209.     ErrorMsgs++;
  210.     if ( !(Flags & DB_STARTUP) && idx != oldidx)
  211.     {
  212.         GetIndString (buf, ERR_STR, idx);
  213.         ParamText (ap0, ap1, ap2, buf);
  214.         i = CautionAlert (RSRC_BASE+ALERT_WARN, nil);
  215.         if (i == ALRT_CANCEL)
  216.             Quit = true;
  217.     }
  218.     if (Flags & DB_STARTUP)
  219.         Quit = true;
  220.     oldidx = idx;
  221.     UseResFile (oldresfile);
  222. }